package uiLayer;

import java.util.NoSuchElementException;
import java.util.Scanner;

import controllerLayer.ProductCtr;

public class ContractorUI {

	private ProductCtr pctr;
	private static ContractorUI instance = null;;
	public ContractorUI() {
		pctr = new ProductCtr();
	}
	public static ContractorUI getInstance()       
	{
		if(instance == null)
		{
			instance = new ContractorUI();
		}
		return instance;
	}
	public void contractorMenuStart() {
		boolean exit = false;
		while(!exit){
		int choice = printContractorMenu();
		switch(choice)
		{
		 case 1: createContractor();
         break;
		 case 2: findByID();
         break;
		 case 3: updateContractor();
         break;
		 case 4: deleteContractor();
		 break;
		 case 5: goBack();
         break;
		}
		}
	}


	private void deleteContractor() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Delete Contractor***");
        System.out.println("ID: ");
        String id = keyboard.nextLine();
       
        
        pctr.deleteContractor(id);
		
	}

	private void goBack() {
		OfficeUI.getInstance().run();
		
	}

	private void updateContractor() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Update Product***");
        
        System.out.println("ID: ");
        String id = keyboard.nextLine();
        System.out.println("Address: ");
        String address = keyboard.nextLine();
        System.out.println("Phone Number: ");
        String phoneNr = keyboard.nextLine();
		pctr.updateContractor(id,address,phoneNr);
		
	}

	private void findByID() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Find Contractor***");
        System.out.println("ID: ");
        String id = keyboard.nextLine();
        
        try{
       System.out.println(pctr.getContractor(id));
        }
        catch(NullPointerException npe){
			System.out.println("Contractor doesn't exist");
					}
		
	}

	private void createContractor() {
		Scanner keyboard = new Scanner(System.in); 
        System.out.print('\f');
        System.out.println("***Create Contractor***");
        System.out.println("ID: ");
        String id = keyboard.nextLine();
        System.out.println("Name: ");
        String name = keyboard.nextLine();
        System.out.println("Address: ");
        String address = keyboard.nextLine();
        System.out.println("Phone Number: ");
        String phoneNr = keyboard.nextLine();
        
		pctr.createContractor(id,name, address, phoneNr);
		
	}

	private int printContractorMenu() {
		Scanner keyboard = new Scanner(System.in);
	        System.out.print('\f');
	        System.out.println("*** Contractor Menu ***");
	        System.out.println("1. Create Contractor");
	        System.out.println("2. Find Contractor");
	        System.out.println("3. Update Contractor");
	        System.out.println("4. Delete Contractor");
	        System.out.println("5. Quit");
	        System.out.println("Your choice #: ");
	        
	        int choice = keyboard.nextInt();
	        return choice;
	}
	




}
